package com.springboot.blog.controller.order;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.springboot.blog.beans.BlogOrder;
import com.springboot.blog.beans.PageBlog;
import com.springboot.blog.dao.OrderDao;
import com.springboot.blog.service.impl.OrderPayServiceImpl;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/user")
public class OrderController {

    @Resource
    private OrderDao orderDao;
    @Resource
    private OrderPayServiceImpl orderPayService;


    @RequestMapping("findorder")
    public String findorder(HttpServletRequest request, String page, String limit){
        String userName = (String) request.getSession().getAttribute("userName");
        PageBlog<BlogOrder> blogOrderPageBlog = orderPayService.pageOrder(Integer.parseInt(page), Integer.parseInt(limit), userName);
        int count = orderDao.AllselectOrderByName(userName);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code",0);
        jsonObject.put("count",count);
        jsonObject.put("data",blogOrderPageBlog);
        return jsonObject.toString();
    }
}
